package com.ruoyi.weldinganalysis.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weldinganalysis.domain.WeldingAnalysisOperator;
import com.ruoyi.weldinganalysis.service.IWeldingAnalysisOperatorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员焊接数据Controller
 * 
 * @author dai
 * @date 2022-12-12
 */
@Controller
@RequestMapping("/welding/operator")
public class WeldingAnalysisOperatorController extends BaseController
{
    private String prefix = "welding/operator";

    @Autowired
    private IWeldingAnalysisOperatorService weldingAnalysisOperatorService;

    @RequiresPermissions("welding:operator:view")
    @GetMapping()
    public String operator()
    {
        return prefix + "/operator";
    }

    /**
     * 查询人员焊接数据列表
     */
    @RequiresPermissions("welding:operator:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WeldingAnalysisOperator weldingAnalysisOperator)
    {
        startPage();
        List<WeldingAnalysisOperator> list = weldingAnalysisOperatorService.selectWeldingAnalysisOperatorList(weldingAnalysisOperator);
        return getDataTable(list);
    }

    /**
     * 导出人员焊接数据列表
     */
    @RequiresPermissions("welding:operator:export")
    @Log(title = "人员焊接数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WeldingAnalysisOperator weldingAnalysisOperator)
    {
        List<WeldingAnalysisOperator> list = weldingAnalysisOperatorService.selectWeldingAnalysisOperatorList(weldingAnalysisOperator);
        ExcelUtil<WeldingAnalysisOperator> util = new ExcelUtil<WeldingAnalysisOperator>(WeldingAnalysisOperator.class);
        return util.exportExcel(list, "人员焊接数据数据");
    }

    /**
     * 新增人员焊接数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人员焊接数据
     */
    @RequiresPermissions("welding:operator:add")
    @Log(title = "人员焊接数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WeldingAnalysisOperator weldingAnalysisOperator)
    {
        return toAjax(weldingAnalysisOperatorService.insertWeldingAnalysisOperator(weldingAnalysisOperator));
    }

    /**
     * 修改人员焊接数据
     */
    @RequiresPermissions("welding:operator:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WeldingAnalysisOperator weldingAnalysisOperator = weldingAnalysisOperatorService.selectWeldingAnalysisOperatorById(id);
        mmap.put("weldingAnalysisOperator", weldingAnalysisOperator);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员焊接数据
     */
    @RequiresPermissions("welding:operator:edit")
    @Log(title = "人员焊接数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WeldingAnalysisOperator weldingAnalysisOperator)
    {
        return toAjax(weldingAnalysisOperatorService.updateWeldingAnalysisOperator(weldingAnalysisOperator));
    }

    /**
     * 删除人员焊接数据
     */
    @RequiresPermissions("welding:operator:remove")
    @Log(title = "人员焊接数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(weldingAnalysisOperatorService.deleteWeldingAnalysisOperatorByIds(ids));
    }
}
